<template>
  <div class="login">
    <div class="login-box">
      <h2>欢迎登录</h2>
      <form @submit.prevent="handleSubmit">
        <div class="form-item">
          <input 
            type="text" 
            v-model="form.username" 
            placeholder="用户名"
            required
          >
        </div>
        <div class="form-item">
          <input 
            type="password" 
            v-model="form.password" 
            placeholder="密码"
            required
          >
        </div>
        <button type="submit">登录</button>
      </form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

const form = ref({
  username: '',
  password: ''
})

const handleSubmit = async () => {
  try {
    // TODO: 调用登录接口
    const redirect = route.query.redirect || '/'
    router.push(redirect)
  } catch (error) {
    console.error('登录失败:', error)
  }
}
</script>

<style scoped lang="scss">
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;

  .login-box {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);

    h2 {
      text-align: center;
      margin-bottom: 30px;
    }

    .form-item {
      margin-bottom: 20px;
      
      input {
        width: 100%;
        padding: 10px;
        border: 1px solid #ddd;
        border-radius: 4px;
        
        &:focus {
          outline: none;
          border-color: #42b983;
        }
      }
    }

    button {
      width: 100%;
      padding: 12px;
      background: #42b983;
      color: #fff;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      
      &:hover {
        background: #3aa876;
      }
    }
  }
}
</style>